home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / interp / mindy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  3.7 KB  |  150 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: mindy.c,v 1.13 94/11/06 20:00:45 rgs Exp $
  27. *
  28. * This file starts everything going.
  29. *
  30. \**********************************************************************/
  31.  
  32. #include "../compat/std-c.h"
  33.  
  34. #include "mindy.h"
  35. #include "init.h"
  36. #include "thread.h"
  37. #include "driver.h"
  38. #include "module.h"
  39. #include "str.h"
  40. #include "bool.h"
  41. #include "list.h"
  42. #include "obj.h"
  43. #include "sym.h"
  44. #include "func.h"
  45. #include "debug.h"
  46. #include "load.h"
  47.  
  48. static void invoke_main(struct thread *thread, obj_t *vals)
  49. {
  50.     obj_t *fp = thread->fp;
  51.     obj_t *args_end = fp - 4;
  52.     obj_t *old_sp = pop_linkage(thread);
  53.     struct variable *var = find_variable(module_BuiltinStuff, symbol("main"),
  54.                      FALSE, FALSE);
  55.  
  56.     if (var == NULL)
  57.     lose("main undefined?");
  58.  
  59.     thread->sp = args_end;
  60.     old_sp[0] = var->value;
  61.     invoke(thread, args_end - old_sp - 1);
  62. }
  63.  
  64. static void startup(struct thread *thread, int nargs)
  65. {
  66.     obj_t *args = thread->sp - nargs;
  67.  
  68.     push_linkage(thread, args);
  69.     set_c_continuation(thread, invoke_main);
  70.     load_do_inits(thread);
  71. }
  72.  
  73. static void missing_arg(char *whose)
  74. {
  75.     fprintf(stderr, "mindy: missing argument to %s option\n", whose);
  76.     exit(1);
  77. }
  78.   
  79. char *exec_file_name;
  80.  
  81. void main(int argc, char *argv[])
  82. {
  83.     struct thread *thread;
  84.     enum pause_reason reason;
  85.     struct variable *var;
  86. #if ! NO_ARGV_0
  87.     char *argv0 = "mindy";
  88. #endif
  89.  
  90.     init();
  91.  
  92.     thread = thread_create(symbol("main"));
  93.     *thread->sp++ = make_raw_function("startup", 0, TRUE, obj_False, FALSE,
  94.                       obj_Nil, obj_ObjectClass,
  95.                       startup);
  96.  
  97.     exec_file_name = argv[0];
  98.     while (*++argv != NULL) {
  99.     if (strcmp(*argv, "-f") == 0) {
  100.         if (*++argv == NULL)
  101.             missing_arg("-f");
  102.         load(*argv);
  103. #if ! NO_SHARP_BANG
  104.         } else if (strcmp(*argv, "-x") == 0) {
  105.         if (*++argv == NULL)
  106.             missing_arg("-f");
  107. #if ! NO_ARGV_0
  108.         if (strcmp(*argv, "-") != 0)
  109.             argv0 = *argv;
  110. #endif
  111.         load(*argv);
  112.         argv += 1;
  113.         break;
  114. #endif
  115. #if ! NO_ARGV_0
  116.     } else if (strcmp(*argv, "-0") == 0) {
  117.         if (*++argv == NULL)
  118.             missing_arg("-0");
  119.         argv0 = *argv;
  120. #endif
  121.         } else {
  122.         break;
  123.     }
  124.     }
  125.  
  126. #if ! NO_ARGV_0
  127.         *thread->sp++ = make_byte_string(argv0);    /* pass command name */
  128. #endif
  129.     while (*argv != NULL)
  130.         *thread->sp++ = make_byte_string(*argv++);
  131.  
  132.     finalize_modules();
  133.  
  134.     while (1) {
  135.     thread_restart(thread);
  136.  
  137.     reason = do_stuff();
  138.     if (reason != pause_NothingToRun)
  139.         invoke_debugger(reason);
  140.  
  141.     var = find_variable(module_BuiltinStuff, symbol("exit"),
  142.                 FALSE, FALSE);
  143.     if (var == NULL)
  144.         lose("main undefined?");
  145.  
  146.     thread = thread_create(symbol("exit"));
  147.     *thread->sp++ = var->value;
  148.     }
  149. }
  150.